import configparser
import logging
import os


class Config:

    def __init__(self):
        rootpath = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
        envfile = open(rootpath + "/env", "r")
        env = envfile.read()
        self.config = configparser.RawConfigParser()
        self.config_path = rootpath + "/conf/config_{0}.ini".format(env)
        logging.error("===============11111")
        logging.error(self.config_path)
        logging.warning("hahahahah===================")
        self.config.read(filenames=self.config_path, encoding='UTF-8')

    def getAllNode(self):
        sections = self.config.sections()
        return sections

    def getRedis(self):
        section_options = self.config.options(section="redis")
        return section_options

    def getnode(self):
        return self.config

    # def getkey(self):
    #     # 返回指定section节点中的的所有option名称【返回值是列表的方式】
    #     section_options = self.config.options(section="ip")  # 返回section中option的值
    #     value = self.config.get(section="ip", option="ip")
    #     print(value, 'value')
    #     # 是否有这个section
    #     print(self.config.has_section(section="ip1"))
    #     print(self.config.items(section="ip"))
